package com.example.travelround.mymusic.main;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.travelround.mymusic.R;

public class MainActivity extends AppCompatActivity {
    private LinearLayout mainFooterLl;
    private TextView content;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mainFooterLl = (LinearLayout) findViewById(R.id.main_footer_ll);
        content = (TextView) findViewById(R.id.footer_artist_tv);

        MainFragment mainFragment = new MainFragment();
        final FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.main_fragment_container, mainFragment);
        transaction.commit();


        mainFooterLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MainActivity.this, DetailActivity.class);
                startActivity(intent);
            }
        });

        MusicBroadCast musicBroadCast = new MusicBroadCast();
        IntentFilter filter = new IntentFilter("musicBroad");
        registerReceiver(musicBroadCast, filter);


    }

    class MusicBroadCast extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            String str = intent.getStringExtra("progress");
            content.setText(str);
        }
    }

}
